package com.muyu.system.domain.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.system.domain.SysLogininfor;
import com.muyu.system.domain.req.SysLogininforAddReq;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * 登录添加模型
 * @description: 登录添加模型
 * @author yangchoashun
 * @date 2025/2/23 17:24
 * @version 1.0
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysLogininforAddModel {
    /**
     * 访问ID
     */
    private Long infoId;
    /**
     * 用户账号
     */
    private String userName;

    /**
     * 状态 0成功 1失败
     */
    private String status;

    /**
     * 地址
     */
    private String ipaddr;

    /**
     * 描述
     */
    private String msg;

    /**
     * 访问时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date accessTime;

    public static SysLogininforAddModel of(SysLogininforAddReq sysLogininforAddReq) {
        return SysLogininforAddModel.builder()
                .infoId(sysLogininforAddReq.getInfoId())
                .userName(sysLogininforAddReq.getUserName())
                .status(sysLogininforAddReq.getStatus())
                .ipaddr(sysLogininforAddReq.getIpaddr())
                .msg(sysLogininforAddReq.getMsg())
                .accessTime(sysLogininforAddReq.getAccessTime())
                .build();
    }

    public static SysLogininfor of(SysLogininforAddModel sysLogininforAddModel) {
        return SysLogininfor.builder()
                .infoId(sysLogininforAddModel.getInfoId())
                .userName(sysLogininforAddModel.getUserName())
                .status(sysLogininforAddModel.getStatus())
                .ipaddr(sysLogininforAddModel.getIpaddr())
                .msg(sysLogininforAddModel.getMsg())
                .accessTime(sysLogininforAddModel.getAccessTime())
                .build();
    }
}
